#include "StdAfx.h"
#include "MainWindow.h"

CMainWindow::~CMainWindow(void)
{
}

BOOL CMainWindow::Init( HINSTANCE hInstance )
{
	WNDCLASSEX wcex;
	ZeroMemory(&wcex, sizeof(WNDCLASSEX));

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= MainWindowProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, IDI_WINLOGO);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= TEXT("MyMainWindowClass");
	//wcex.hIconSm		= LoadIcon(wcex.hInstance, IDI_SMALL);

	RegisterClassEx(&wcex);

	m_hWnd = CreateWindow(TEXT("MyMainWindowClass"), TEXT("Peter's RPG"), WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);

	//m_pKeyboardEvent = new KeyboardEvent();

	ShowWindow(m_hWnd, SW_SHOW);
	UpdateWindow(m_hWnd);

	return TRUE;
}

VOID CMainWindow::UnInit()
{
	if (m_hWnd)
	{
		CloseHandle(m_hWnd);
	}
}

LRESULT __stdcall CMainWindow::MainWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch (message)
	{
	case WM_KEYUP:
		if (wParam == VK_ESCAPE)
		{
			PostQuitMessage(0);
		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
